Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use lockfiles when determining what packages changed across commits #3250

Conversation

chris-olszewski
Copy link
Member

@chris-olszewski chris-olszewski commented Jan 10, 2023

This PR attempts to address #2162

This PR was written to be conservative by nature and it will mark packages as changed on almost any lockfile change that isn't just a version bump.

Notable changes:

  • Extended SCM interface as we need to be able to reconstruct old lockfile
  • Refactored calculation of the transitive closure of the package graph so a full Context object isn't required
  • Merged TransitiveDeps and ExternalDeps as they contained almost identical information

I haven't been able to fully test this, but from a quick spot check of pnpm it seems to behave as expected.
Needed testing:

  • Npm
  • Yarn
  • Yarn2+
  • Pnpm

@vercel
Copy link

vercel bot commented Jan 10, 2023

@chris-olszewski is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jan 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-designsystem-docs 🔄 Building (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-native-web 🔄 Building (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-svelte-web 🔄 Building (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 2, 2023 at 0:07AM (UTC)
turbo-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 2, 2023 at 0:07AM (UTC)
6 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Feb 2, 2023 at 0:07AM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2023 at 0:07AM (UTC)

@chris-olszewski chris-olszewski force-pushed the chrisolszewski/turbo-537-improve-changed-workspace-filters-use-of branch from a00f42c to 664038a Compare January 30, 2023 21:32
@chris-olszewski chris-olszewski marked this pull request as ready for review January 30, 2023 21:43
@chris-olszewski chris-olszewski requested a review from a team as a code owner January 30, 2023 21:43
Copy link
Contributor

@NicholasLYang NicholasLYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions but this makes sense overall.

return resolvedPkgs, nil
}

func transitiveClosureHelper(wg *errgroup.Group, pkg *fs.PackageJSON, lockfile lockfile.Lockfile, unresolvedDirectDeps map[string]string, resolvedDeps mapset.Set) {
for directDepName, unresolvedVersion := range unresolvedDirectDeps {
directDepName := directDepName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of these lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't copy the values here then it'll resolve as the same value in every iteration of the loop: https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable

I'm so excited for Rust

pkg.TransitiveDeps = append(pkg.TransitiveDeps, lockfilePkg.Key)
pkg.Mu.Unlock()
resolvedDepsSet.Add(fmt.Sprintf("%s@%s", lockfilePkg.Key, lockfilePkg.Version))
resolvedDeps.Add(lockfilePkg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we can get rid of the lock here? Is it because we're only mutating resolvedDeps now? Are there any race conditions due to the wg.Go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we needed the lock because each goroutine that was spun up via the working group could try to append TransitiveDeps and go slices aren't thread safe. mapset.Set is threadsafe so we don't need to lock anything up

@chris-olszewski chris-olszewski merged commit 368b715 into vercel:main Feb 3, 2023
mehulkar pushed a commit that referenced this pull request Feb 3, 2023
…mits (#3250)

This PR attempts to address #2162

This PR was written to be conservative by nature and it will mark
packages as changed on almost any lockfile change that isn't just a
version bump.

Notable changes:
- Extended SCM interface as we need to be able to reconstruct old
lockfile
- Refactored calculation of the transitive closure of the package graph
so a full `Context` object isn't required
- Merged `TransitiveDeps` and `ExternalDeps` as they contained almost
identical information

I haven't been able to fully test this, but from a quick spot check of
pnpm it seems to behave as expected.
Needed testing:

- [x] Npm
- [x] Yarn
- [x] Yarn2+
- [x] Pnpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants